angular.module('liemallfodder')
  .factory('MaterialApi', function (ApiManager) {
    var api = {};

    /**
     *  素材广告图
     *  @return List<Material> : {id,cover}
     * */
    api.listBanner = function (success, failure) {
      var body = {
        name: "/MaterialApi/banner",
        data: {}
      };
      get(ApiManager, body, success, failure);
    };

    /**
     *  素材分类列表
     *  @return List<Category> : {id,name,image,thumb_image}
     * */
    api.listCategory = function (success, failure) {
      var body = {
        name: "/MaterialApi/listCategory",
        data: {}
      };
      get(ApiManager, body, success, failure);
    };

    /**
     *  素材子分类列表
     *  @return List<Category> : {id,name,image,thumb_image}
     * */
    api.listSubCategory = function (category_id, success, failure) {
      var body = {
        name: "/MaterialApi/listSubCategory",
        data: {
          "category_id": category_id
        }
      };
      get(ApiManager, body, success, failure);
    };

    /**
     *  素材列表
     *  @return List<Material> : {id,title}
     * */
    api.listMaterial = function (subcategory_id, success, failure) {
      var body = {
        name: "/MaterialApi/listMaterial",
        data: {
          "category_id": subcategory_id
        }
      };
      get(ApiManager, body, success, failure);
    };

    /**
     *  素材详情
     *  @return Material : {title,content,create_time}
     * */
    api.materialDetail = function (material_id, success, failure) {
      var body = {
        name: "/MaterialApi/detail",
        data: {
          "material_id": material_id
        }
      };
      get(ApiManager, body, success, failure);
    };

    return api;
  });
